//
//  GSStrategyAllCell.m
//  GameSky
//
//  Created by lanou on 16/1/10.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSStrategyAllCell.h"

#define kMargin 10

@implementation GSStrategyAllCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        self.coverImage = [[UIImageView alloc] initWithFrame:CGRectMake(kMargin, kMargin, kScreenWidth * 0.4, 100)];
        [self.contentView addSubview:self.coverImage];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.coverImage.right + kMargin, self.coverImage.top, kScreenWidth - kMargin * 4 - 205, 60)];
        self.titleLabel.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor grayColor]);
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        self.titleLabel.numberOfLines = 0;
        [self.contentView addSubview:self.titleLabel];
        
        self.commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.left, self.titleLabel.bottom + kMargin, self.titleLabel.width, 30)];
        self.commentLabel.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor grayColor]);
        self.commentLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:self.commentLabel];
        
        self.subButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.subButton.frame = CGRectMake(kScreenWidth - kMargin - 45, self.coverImage.center.y - 10, 40, 20);
        self.subButton.backgroundColor = [UIColor redColor];
        self.subButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.subButton setTitle:@"订阅" forState:(UIControlStateNormal)];
        [self.subButton addTarget:self action:@selector(subButtonClick:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.contentView addSubview:self.subButton];
    }
    return self;
}
// 订阅按钮点击方法;
- (void)subButtonClick:(UIButton *)button
{
    button.selected = !button.selected;
    if (button.selected) {
        button.backgroundColor = [UIColor lightGrayColor];
        [button setTitle:@"退订" forState:(UIControlStateSelected)];
        [button setTitleColor:[UIColor redColor] forState:(UIControlStateSelected)];
    } else {
        button.backgroundColor = [UIColor redColor];
        [button setTitle:@"订阅" forState:(UIControlStateNormal)];
    }
}

- (void)setModel:(GSStrategyMainModel *)model
{
    _model = model;
    [self.coverImage sd_setImageWithURL:[NSURL URLWithString:model.thumbnailUrl] placeholderImage:kPHImage];
    self.titleLabel.text = model.title;
    self.commentLabel.text = [NSString stringWithFormat:@"%@人订阅",model.favoriteCnt];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
